//
//  GasHomeHeaderView.m
//  NtoccDriverNew
//
//  Created by niyongsheng on 2022/10/17.
//  Copyright © 2022 GCY. All rights reserved.
//

#import "GasHomeHeaderView.h"

@interface GasHomeHeaderView ()
@property (weak, nonatomic) IBOutlet UIView *sectionView0;
@property (weak, nonatomic) IBOutlet UIView *sectionView1;
@property (weak, nonatomic) IBOutlet UIView *sectionView2;

@property (weak, nonatomic) IBOutlet UIView *searchView;
@property (weak, nonatomic) IBOutlet UITextField *searchTF;
@end

@implementation GasHomeHeaderView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        NSBundle *bundle = [NSBundle bundleForClass:[self class]];
        UINib *nib = [UINib nibWithNibName:NSStringFromClass([self class])
                                    bundle:bundle];
        
        UIView *view = [nib instantiateWithOwner:self options:nil][0];
        
        view.frame = self.bounds;
        view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        self.bottomView.hidden = YES;
        [self addSubview:view];
        [self setupView];
    }
    return self;
}

- (void)setupView {
    ViewRadius(_searchView, 5)
    
    _sectionView0.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap0 = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        if (_sectionBlock) {
            self.sectionBlock(0);
        }
    }];
    [_sectionView0 addGestureRecognizer:tap0];
    
    _sectionView1.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        if (_sectionBlock) {
            self.sectionBlock(1);
        }
    }];
    [_sectionView1 addGestureRecognizer:tap1];
    
    _sectionView2.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        if (_sectionBlock) {
            self.sectionBlock(2);
        }
    }];
    [_sectionView2 addGestureRecognizer:tap2];
}

- (IBAction)searchBtnOnclicked:(UIButton *)sender {
    if (_searchBlock) {
        self.searchBlock(_searchTF.text);
    }
}

@end
